#include <bits/stdc++.h>

#define int long long

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> arr(n + 10);
    for(int i = 1; i <= n; i ++)
    {
        cin >> arr[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(i % 2 == 0)
        {
            if(arr[i - 1] > arr[i]) ans += arr[i - 1] - arr[i],arr[i - 1] = arr[i];
            if(arr[i + 1] > arr[i]) ans += arr[i + 1] - arr[i],arr[i + 1] = arr[i];
            if(arr[i - 1] + arr[i + 1] > arr[i])
            {
                ans += arr[i - 1] + arr[i + 1] - arr[i];
                arr[i + 1] -= arr[i - 1] + arr[i + 1] - arr[i];
            }
        }
    }
    cout << ans << endl;
}

signed main()
{
    int t;
    cin >> t;
    while(t --)
    {
        solve();
    }
}